

<template>
<div>
<input type="number" maxlength="11" placeholder="请输入手机号" v-model="parameter.telphone">
<input type="number" placeholder="请输入验证码" v-model="parameter.smsCode">
<button @click="getVerificaCode">获取验证码</button>
<div class="clearfix"><p class="fl" @click="registered">立即注册</p><p class="fr" @click="accountLogin()">账号密码登录</p></div>
<button @click="logIn()">登录</button>
</div>
</template>

<script>
export default {    
  data(){
    return{
      parameter:{
         telphone:'',
        smsCode:'',
      }
     
    }
  },

  methods: {
  accountLogin(){
    wx.navigateTo({
        url:"/pages/login/accountLogin/main"
      })
  },
  registered(){
    wx.navigateTo({
        url:"/pages/login/registered/main"
      })
  },
  getVerificaCode(){
    var that=this
    if(that.parameter.telphone==''){
       wx.showToast({
          title:'手机号不能为空',
          icon: "none",
          duration: 1000
        });
        return false
    }
    if(!(/^1[3456789]\d{9}$/.test(that.parameter.telphone))){ 
        wx.showToast({
          title:'请输入正确的手机号',
          icon: "none",
          duration: 1000
        });
        return false; 
    }
    that.$api.user.sendSms(that.parameter).then(row=>{     
            if(row.status===0){
             console.log(row)
            }else{
              wx.showToast({
                title: row.message,
                icon: "none",
                duration: 1000
              });
            }
        })
  },
  logIn(){
       var that=this
       if(that.parameter.telphone==''){
          wx.showToast({
              title:'手机号不能为空',
              icon: "none",
              duration: 1000
            });
            return false
        }
       if(!(/^1[3456789]\d{9}$/.test(that.parameter.telphone))){ 
          wx.showToast({
            title:'请输入正确的手机号',
            icon: "none",
            duration: 1000
          });
          return false; 
      }
       if(that.parameter.smsCode==''){
          wx.showToast({
              title:'验证码不能为空',
              icon: "none",
              duration: 1000
            });
            return false
        }
       //发起网络请求
        that.$api.user.loginBySms(that.parameter).then(row=>{     
            if(row.status===0){
             console.log(row)
            }else{
              wx.showToast({
                title: row.message,
                icon: "none",
                duration: 1000
              });
            }
        })
    },
  }
}
</script>

<style scoped>

</style>
